import { createRouter, createWebHashHistory } from 'vue-router'
import { App } from 'vue'

import { setupLayouts } from 'virtual:generated-layouts'
import generatedRoutes from 'virtual:generated-pages'

console.log(setupLayouts(generatedRoutes))
const router = createRouter({
  history: createWebHashHistory(),
  strict: true,
  routes: setupLayouts(generatedRoutes)
})

// 路由导航守卫
router.beforeEach((to) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - ${import.meta.env.VITE_APP_TITLE}` // 修改这里
  }
})

export const setupRouter = (app: App<Element>) => {
  app.use(router)
}

export default router
